package com.eling.elcms.community.service.impl;

import com.eling.elcms.community.dao.IDepartmentDao;
import com.eling.elcms.community.event.DepartmentAfterSealUnSealEvent;
import com.eling.elcms.community.model.Department;
import com.eling.elcms.community.service.IDepartmentManager;
import com.eling.elcms.core.event.EventEngine;
import com.eling.elcms.core.service.impl.GenericManagerImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class DepartmentManagerImpl extends GenericManagerImpl<Department, Long> implements IDepartmentManager {
	
	@Autowired
    public void setDepartmentDao(IDepartmentDao dao) {
        this.dao = dao;
    }
	@Override
	public Department seal(Long pkDepartment) {
		Department department=get(pkDepartment);
		Department departmentsave;
		if(department.getSeal()){
			department.setSeal(false);
			departmentsave=save(department);
		}
		else{ 
		    department.setSeal(true);
		    departmentsave=save(department);
		}
		// 发送事件
		DepartmentAfterSealUnSealEvent susEvent = new DepartmentAfterSealUnSealEvent(department);
		EventEngine.dispatch(susEvent);
    	return departmentsave;
	}
	
}
